//
//  AccountViewController.m
//  iStore
//
//  Created by Geek on 15/4/21.
//  Copyright (c) 2015年 mirrtalk. All rights reserved.
//

#import "PublicityViewController.h"
#import "PublicityTableViewCell.h"
#import "RequestEngine.h"

@interface PublicityViewController () <UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation PublicityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"宣传效果";
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.allowsSelection=NO;
    _myArray = [[NSMutableArray alloc]init];
    _tableView.tableFooterView = [[UIView alloc]init];
    
    self.automaticallyAdjustsScrollViewInsets = false;
    
    NSString *userID = [[NSUserDefaults standardUserDefaults]objectForKey:kUserId];
    [self activityStart];
    [RequestEngine RequestEngineWithDic:@{@"userID":userID} URL:@"/queryReleaseRepord" completed:^(NSString *errorcode,NSDictionary *resultDict) {
        [self activityStop];
        if ([errorcode isEqualToString:@"0"]) {
            [self createAccountBook:resultDict];
            _myArray = resultDict[@"ADReleaseRepord"];
            [_tableView reloadData];
            if (_myArray.count == 0 || _myArray == nil) {
                [self createNull];
            }
        }        
    }];
}
- (void)createNull
{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 140, ScreenWidth, 40)];
    label.text = @"您还没有消息喔~";
    label.textColor = [UIColor blackColor];
    [label setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:label];
}

- (void)createAccountBook:(NSDictionary*)resultDict
{
    _adverSum.text=[NSString stringWithFormat:@"%@",[resultDict objectForKey:@"adverSum"]];
    _receivedSum.text=[NSString stringWithFormat:@"%@",[resultDict objectForKey:@"receivedSum"]];
    _releasedSum.text=[NSString stringWithFormat:@"%@",[resultDict objectForKey:@"releasedSum"]];
    _costSum.text=[NSString stringWithFormat:@"%.2f",[[resultDict objectForKey:@"costSum"] floatValue]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _myArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *cellID = @"cellID";
    PublicityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"PublicityTableViewCell" owner:self options:nil]lastObject];
    }
    [cell refreshData:[_myArray objectAtIndex:indexPath.row]];
    
    return cell;

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.333
}


@end
